<head>
	<meta charset="UTF-8">
	<title>Ulmart Product List</title>
	<script src="<?php echo $this->getSkinUrl().'js/pikaday.min.js';?>"></script>
	<script src="<?php echo $this->getBaseUrl().'js/em/jquery-1.11.3.min.js';?>"></script>
	<link rel="stylesheet" type="text/css" href="<?php echo $this->getSkinUrl() ?>css/pikaday.css"/>
<?php
	$products = $this->getCollection();
	$rootCatId = '2';
	$catlistHtml = $this->getTreeCategories($rootCatId);
	/*先获取产品信息，才能获取分页*/
	$pager = $this->getPager();
	$fielder = $this->getFielder();
	$totalSize = $this->total;
?>

<style type="text/css">
	.content{width:98%;background:#eee;font-size:12px;}
	table{border-spacing:0px;}
	td{border:1px solid gray;}
	textarea{width:98%;height:215px;overflow:auto;}
	.col1{width:5%;}
	.col2{width:12%;}
	.col3{width:60%;}
	.col4{width:9%;}
	.col6{width:9%;}
	td.sp1{width:15%;}
	.t2{width:100%;height:100%;}
	.header{height:35px;}
</style>
<script type="text/javascript">
function submit_form(){
	var form = document.getElementById('product_list');
	form.submit();
}
</script>

</head>
<body>
	<div class="header">
		<div class="menu">
			<form action="" method="get">
			<!-- <span>
				<span>demo</span><br/>
				<?php //echo $catlistHtml; ?>	
			</span>
			<span><?php //echo $pager; ?></span>
			<span><?php //echo $fielder; ?></span>
			<span>Total: <?php //echo $totalSize;?></span>
			<input type="text" name="entityId" placeholder="亲!请输入正确entutyid">
			<input type="text" name="sku" placeholder="亲!请输入正确SKU">
			<input type="text" name="startTime" placeholder="亲!请输入开始正确时间" id="starttime">
			<input type="text" name="endTime" placeholder="亲!请输入结束正确时间" id="endTime"/>
			<input type="submit" value="<?php //echo $this->__('Submit');?>" />
			</form>  -->
			<table border="1">
			  <tr>
			    <td><?php echo $this->__('catlistHtml');?></td>
			    <td><?php echo $this->__('pager');?></td>
			    <td><?php echo $this->__('fielder');?></td>
			    <td><?php echo $this->__('Total');?></td>
			    <td colspan="2"><?php echo $this->__('entityId or Sku');?></td> 
			    <td colspan="2"><?php echo $this->__('Time');?></td>
			  </tr>
			  <tr>
			    <td><?php echo $catlistHtml; ?></td>
			   	<td><?php echo $pager; ?></td>
			   	<td><?php echo $fielder; ?></td>
			   	<td><?php echo $totalSize;?></td>
			   	<td colspan="2"><input type="text" name="sku_id" ></td>
			   	<td><input type="text" name="startTime" id="starttime" style="width:140px;"></td>
			   	<td><input type="text" name="endTime" id="endTime" style="width:140px;"/></td>
			   	<td rowspan="2"><input type="submit" value="<?php echo $this->__('Submit');?>" /></td>
			  </tr>
			</table>
			</form>
		</div>
	</div>

	<br/>
<script type="text/javascript">

    var starttime = new Pikaday(
    {
        field: document.getElementById('starttime'),//
        firstDay: 1,
        minDate: new Date('2010-01-01'),
        maxDate: new Date('2020-12-31'),
        yearRange: [2000,2020]
    });
    var endTime = new Pikaday(
    {
        field: document.getElementById('endTime'),//
        firstDay: 1,
        minDate: new Date('2010-01-01'),
        maxDate: new Date('2020-12-31'),
        yearRange: [2000,2020]
    });
</script>



	<div class="content">
	<?php if($products): ?>
	<table>
	<?php foreach($products as $key => $product): ?>
		<?php
			$imgUrl = (string)Mage::helper('catalog/image')->init($product, 'thumbnail')->resize(150,150);
			$description = Mage::helper('core')->stripTags($product->getShortDescription());
			if(mb_strlen($description,'UTF-8') > 200){
				$shortDescription = mb_substr($description,0,200,'UTF-8') . '...';
				$isShow = true;
			}else{
				$shortDescription = $description;
				$isShow = false;
			}
			$isSelected = $product->getIsSelected();
			$comment = $product->getComment();
			$isConfirm = $product->getIsConfirm();
		?>

		<tr class="row_item">
			
			<td class="col2"><a href="<?php echo $this->getUrl('ulmart/product/downloadimage/id/'.$product->getId());?>"><img src="<?php echo $imgUrl; ?>"></a></td>
			
			<td class="col3" valign="middle">
				<div style="height:230px;">
				<table class="t2" style="height:100%;border:none;">
					<tr>
						<td class="sp1">Id</td>
						<td class="sp2"><?php echo $product->getId(); ?></td>
					</tr>
					<tr>
						<td class="sp1">Sku</td>
						<td class="sp2"><?php echo $product->getSku(); ?></td>
					</tr>
					<tr>
						<td class="sp1">Brand</td>
						<td class="sp2"><?php echo $product->getCommonBrand(); ?></td>
					</tr>
					<tr>
						<td class="sp1"><?php echo $this->__('Name'); ?></td>
						<td class="sp2"><?php echo $product->getName(); ?></td>
					</tr>
					<tr>
						<td class="sp1"><?php echo $this->__('Description'); ?></td>
						<td class="sp2"><?php echo $shortDescription; ?>
						<?php if($isShow): ?>
						<a href="javascript:TextWin.show('<?php echo htmlspecialchars($description); ?>');"><?php echo $this->__('More');?></a>
						<?php endif; ?>
						</td>
					</tr>
					<tr>
						<td class="sp1"><?php echo $this->__('Special_Price'); ?></td>
						<td class="sp2"><?php echo round(Mage::helper('directory')->currencyConvert($product->getSpecialPrice(), 'USD', 'RUB'),2); ?></td>
					</tr>
					<tr>
						<td class="sp1"><?php echo $this->__('Price'); ?></td>
						<td class="sp2"><?php echo round(Mage::helper('directory')->currencyConvert($product->getPrice(), 'USD', 'RUB'),2); ?></td>
					</tr>
				</table>
				</div>
			</td>

			<td class="col4">
				<input type="radio" class="is_select" name="is_select_<?php echo $key;?>" value="1" <?php echo $isSelected == '1' ? 'checked="checked"' : '';?> /><?php echo $this->__('Yes');?><br/>
				<input type="radio" class="is_select" name="is_select_<?php echo $key;?>" value="2" <?php echo $isSelected == '2' ? 'checked="checked"' : '';?> /><?php echo $this->__('No');?>
				<hr></hr>

				<input type="radio" class="is_confirm" name="is_confirm_<?php echo $key;?>" value="2" <?php echo $isConfirm == '2' ? 'checked="checked"' : '';?>>
				<?php echo $this->__('Uploaded');?><br/>

				<input type="radio" class="is_confirm" name="is_confirm_<?php echo $key;?>" value="1" <?php echo $isConfirm == '1' ? 'checked="checked"' : '';?>>
				<?php echo $this->__('Not uploaded');?>
			</td>
			<!-- <td class="col6">
				<input type="radio" class="is_confirm" name="is_confirm_<?php echo $key;?>" value="2" <?php echo $isConfirm == '2' ? 'checked="checked"' : '';?>>
				<?php echo $this->__('Uploaded');?><br/>

				<input type="radio" class="is_confirm" name="is_confirm_<?php echo $key;?>" value="1" <?php echo $isConfirm == '1' ? 'checked="checked"' : '';?>>
				<?php echo $this->__('Not uploaded');?>
			</td> -->
			<td class="col5">
				<textarea class="comment"><?php echo $comment;?></textarea>
			</td>
			
			<td>
				<button onclick="save(this, '<?php echo $product->getData('entity_id');?>','<?php echo $product->getData('id');?>')"><?php echo $this->__('Save');?></button>
			</td>
		</tr>
	<?php endforeach; ?>
	</table>
	<?php endif; ?>
	</div>
	<script type="text/javascript">
	
	function quest(){
		
	}
	
	function save(btn, entity_id, id) {
		var data = {}, tr = $(btn).parents('tr');
		data.product_id = entity_id;
		data.id = id;
		data.comment = tr.find('.comment').val();
		data.is_selected = null;
		tr.find('.is_select').each(function() {
			if ($(this).is(':checked')) {
				data.is_selected = $(this).val();
				return false;
			}
		});

		tr.find('.is_confirm').each(function(){
			if($(this).is(':checked')){
				data.is_confirm = $(this).val();
			}
		});

		$.post('<?php echo $this->getUrl('ulmart/product/save');?>', {data: data}, function(response) {
			notice(btn, response);
		});
		
	}
	function notice(obj, msg) {
		var
			left = $(obj).offset().left,
			top = $(obj).offset().top,
			node = $('<div style="position:absolute;top:0;left:0;z-index:99;padding:5px;font-size:12px;background-color:#0f0;visibility:hidden;border-radius:3px;">' + msg + '</div>');
		$('body').append(node);
		node.css({left: left, top: top - 30, visibility: 'visible'}).animate({opacity: 0, top: top - 70}, 1500, function() {
			node.remove();
		});
	}
	
	var TextWin = {
		show: function(text) {
			var
				h = $(window).height(),
				w = $(window).width(),
				obj = $('<div class="TextWin_body" style="width:600px;position:fixed;top:0;left:0;visibility:hidden;z-index:999;padding:20px;border-radius:5px;background-color:#fff;">' + text + '</div>');
			$('body').append('<div class="TextWin_cover" onclick="TextWin.remove(this)" style="position:fixed;top:0;left:0;width:100%;height:100%;z-index:998;background-color:#000;opacity:0.2;filter:alpha(opacity=20);"></div>');
			$('body').append(obj);
			obj.css({left: (w - obj.width()) / 2, top: (h - obj.height()) / 2, visibility: 'visible'});
		},
		remove: function(dom) {
			$(dom).next('.TextWin_body').animate({opacity: 0, top: 0}, 1000, function() {
				$(dom).next('.TextWin_body').remove();
				$(dom).remove();
			});
		}
	}

	</script>
</body>

